<template>
  <div class="md-layout-info">
    <div class="user-bg">
      <div class="user-box">
        <div class="avatar-box">
          <img src="@/assets/img/avatar.png" alt="">
        </div>
        <div class="user-info">
          <p class="u-name">{{userInfo.userName}}</p>
          <ul>
            <li class="u-tip">
              <em>{{sInfo.likeCount}}</em>
              <span>点赞</span>
            </li>
            <li class="u-tip">
              <em>{{sInfo.collectCount}}</em>
              <span>收藏</span>
            </li>
            <li class="u-tip">
              <em>{{sInfo.viewCount}}</em>
              <span>观看</span>
            </li>
            <li class="u-tip">
              <em>{{sInfo.answerCount}}</em>
              <span>答题</span>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { selectUserStudyStatistics } from '@/axios/user'
export default {
  name: 'MdLayoutInfoComponent',
  data () {
    return {
      sInfo: {
        likeCount: 0,
        collectCount: 0,
        viewCount: 0, 
        answerCount: 0
      }
    }
  },
  created () {
    this.selectUserStudyStatistics()
  },
  methods: {
    async selectUserStudyStatistics () {
      const res = await selectUserStudyStatistics()
      if (res.code === 200) {
        this.sInfo = res.data
      }
    }
  },
  computed: {
    isLogin () {
      return window.localStorage.getItem('isLogin')
    },
    userInfo () {
      return JSON.parse(window.localStorage.getItem('userInfo'))
    }
  }
}
</script>
<style lang="less" scoped>
.md-layout-info {
  width: 100%;
  padding-top: 30px;
  .user-bg {
    width: 100%;
    height: 148px;
    background: url('../../assets/img/user-bg.png') no-repeat center top #000;
    background-size: cover;
    margin-bottom: 40px;
    .user-box {
      width: 1200px;
      margin: 0 auto;
      display: flex;
      align-items: center;
      .avatar-box {
        border: 4px solid #fff;
        box-shadow: 0 4px 8px 0 rgba(7,17,27,.1);
        width: 140px;
        height: 140px;
        position: relative;
        border-radius: 50%;
        background: #fff;
        overflow: hidden;
        top: 24px;
        flex-shrink: 0;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .user-info {
        flex: 1;
        padding: 0 40px 0 30px;
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-between;
        .u-name {
          font-weight: 600;
          text-align: left;
          font-size: 24px;
          color: #fff;
          line-height: 28px;
        }
        ul {
          display: flex;
          align-items: center;
        }
        .u-tip {
          margin-right: 20px;
          em {
            display: block;
            text-align: center;
            font-weight: 700;
            font-size: 24px;
            color: rgba(255,255,255,.8);
            line-height: 28px;
          }
          span {
            display: block;
            text-align: center;
            font-size: 14px;
            color: rgba(255,255,255,.8);
            line-height: 20px;
            margin-top: 4px;
          }
        }
      }
    }
  }
}
</style>